{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Maximum Number of Pairs in Array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #counting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #计数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: numberOfPairs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #数组能形成多少数对"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 。在一步操作中，你可以执行以下步骤：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>从 <code>nums</code> 选出 <strong>两个</strong> <strong>相等的</strong> 整数</li>\n",
    "\t<li>从 <code>nums</code> 中移除这两个整数，形成一个 <strong>数对</strong></li>\n",
    "</ul>\n",
    "\n",
    "<p>请你在 <code>nums</code> 上多次执行此操作直到无法继续执行。</p>\n",
    "\n",
    "<p>返回一个下标从 <strong>0</strong> 开始、长度为 <code>2</code> 的整数数组 <code>answer</code> 作为答案，其中<em> </em><code>answer[0]</code><em> </em>是形成的数对数目，<code>answer[1]</code> 是对 <code>nums</code> 尽可能执行上述操作后剩下的整数数目。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [1,3,2,1,3,2,2]\n",
    "<strong>输出：</strong>[3,1]\n",
    "<strong>解释：</strong>\n",
    "nums[0] 和 nums[3] 形成一个数对，并从 nums 中移除，nums = [3,2,3,2,2] 。\n",
    "nums[0] 和 nums[2] 形成一个数对，并从 nums 中移除，nums = [2,2,2] 。\n",
    "nums[0] 和 nums[1] 形成一个数对，并从 nums 中移除，nums = [2] 。\n",
    "无法形成更多数对。总共形成 3 个数对，nums 中剩下 1 个数字。</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [1,1]\n",
    "<strong>输出：</strong>[1,0]\n",
    "<strong>解释：</strong>nums[0] 和 nums[1] 形成一个数对，并从 nums 中移除，nums = [] 。\n",
    "无法形成更多数对。总共形成 1 个数对，nums 中剩下 0 个数字。</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [0]\n",
    "<strong>输出：</strong>[0,1]\n",
    "<strong>解释：</strong>无法形成数对，nums 中剩下 1 个数字。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= nums.length &lt;= 100</code></li>\n",
    "\t<li><code>0 &lt;= nums[i] &lt;= 100</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [maximum-number-of-pairs-in-array](https://leetcode.cn/problems/maximum-number-of-pairs-in-array/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [maximum-number-of-pairs-in-array](https://leetcode.cn/problems/maximum-number-of-pairs-in-array/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,3,2,1,3,2,2]', '[1,1]', '[0]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        a={}\n",
    "        for i in nums:\n",
    "            if i in a:a[i]+=1\n",
    "            else:a[i]=1\n",
    "        x,y=0,0\n",
    "        for i in a:\n",
    "            x+=a[i]//2\n",
    "            y+=a[i]%2\n",
    "        return x,y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        snum = set()\n",
    "        result = 0\n",
    "        for item in nums:\n",
    "            if item in snum:\n",
    "                snum.remove(item)\n",
    "                result += 1\n",
    "            else:\n",
    "                snum.add(item)\n",
    "        return [result, len(nums) - result*2]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        c = Counter(nums)\n",
    "        one = 0\n",
    "        two = 0\n",
    "        for i in c:\n",
    "            one += c[i]//2\n",
    "            two += c[i]%2\n",
    "        return [one,two]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        nums_counter = Counter(nums)\n",
    "        return [sum(i//2 for i in nums_counter.values()),sum(1 for j in nums_counter.values() if j % 2 ==1)]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        c = Counter(nums)\n",
    "        ans = [0, 0]\n",
    "        for k, v in c.items():\n",
    "            if v % 2 != 0:\n",
    "                ans[1] += 1\n",
    "            ans[0] += (v // 2)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        ans = [0, 0]\n",
    "        n = len(nums)\n",
    "        nums = sorted(nums)\n",
    "        mask = [True] * n\n",
    "        for i in range(n-1):\n",
    "            if mask[i] == True:\n",
    "                for j in range(i+1, n):\n",
    "                    if nums[i]==nums[j] and mask[j]==True:\n",
    "                        mask[i] = False\n",
    "                        mask[j]=False\n",
    "                        ans[0]+=1\n",
    "                        break\n",
    "        ans[1] = sum(mask)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        hash_s = set()\n",
    "        cnt = 0\n",
    "        for i in nums:\n",
    "            if i not in hash_s:\n",
    "                hash_s.add(i)\n",
    "            else:\n",
    "                hash_s.remove(i)\n",
    "                cnt += 1\n",
    "        return [cnt,n-2*cnt]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        ans = [0, 0]\n",
    "        cnt = Counter()\n",
    "        for x in nums:\n",
    "            cnt[x] += 1\n",
    "        for y in cnt:\n",
    "            ans[0] += cnt[y] // 2\n",
    "            ans[1] += cnt[y] % 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        nums_counter = Counter(nums)\n",
    "        res = [0,0]\n",
    "        for i in nums_counter.values():\n",
    "            res[0]+=i//2\n",
    "            if i % 2 ==1:\n",
    "                res[1]+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        dic = Counter(nums)\n",
    "        ans = [0, 0]\n",
    "        for v in dic.values():\n",
    "            ans[0] += v // 2\n",
    "            ans[1] += v % 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        d = {}\n",
    "        for num in nums:\n",
    "            if num in d:\n",
    "                d[num] += 1\n",
    "            else:\n",
    "                d[num] = 1\n",
    "        ans1 = 0\n",
    "        ans2 = 0\n",
    "        for val in d.values():\n",
    "            ans1 += val % 2\n",
    "            ans2 += val // 2\n",
    "        return [ans2, ans1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        nums_counter = Counter(nums)\n",
    "        res=[0,0]\n",
    "        for i in nums_counter.values():\n",
    "            res[0]+=i // 2\n",
    "            res[1]+=i % 2\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        c = Counter(nums)\n",
    "        answer = [0, 0]\n",
    "        for i in c.values():\n",
    "            answer[0] += i // 2\n",
    "            answer[1] += i & 1\n",
    "        return answer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        hash_s = set()\n",
    "        cnt = 0\n",
    "        for i in nums:\n",
    "            if i not in hash_s:\n",
    "                hash_s.add(i)\n",
    "            else:\n",
    "                hash_s.remove(i)\n",
    "                cnt += 1\n",
    "        return [cnt,n-2*cnt]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        nums_counter = Counter(nums)\n",
    "        res=[0,0]\n",
    "        for i in nums_counter.values():\n",
    "            if i % 2 == 0:\n",
    "                res[0]+=i // 2\n",
    "            elif i % 2 == 1 and i // 2 == 0:\n",
    "                res[1]+=1\n",
    "            elif i % 2 == 1 and i // 2 != 0:\n",
    "                res[1]+=1\n",
    "                res[0]+=i // 2\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        cnt = defaultdict(bool)\n",
    "        res = 0\n",
    "        for num in nums:\n",
    "            cnt[num] = not cnt[num]\n",
    "            if not cnt[num]:\n",
    "                res += 1\n",
    "        return [res, len(nums) - 2 * res]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        cnt=Counter(nums)\n",
    "        ans=[0,0]\n",
    "        for i in cnt:\n",
    "            ans[0]=ans[0]+cnt[i]//2\n",
    "            ans[1]=ans[1]+cnt[i]%2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        nums.sort()\n",
    "        count = 0\n",
    "        ans = []\n",
    "        for i in range(0,len(nums)):\n",
    "            if len(ans) ==0:\n",
    "                ans.append(nums[i])\n",
    "            else:\n",
    "                if nums[i] == ans[len(ans)-1] and len(ans)>0:\n",
    "                    ans.pop()\n",
    "                    count += 1\n",
    "                else:\n",
    "                    ans.append(nums[i])\n",
    "        return [count,len(ans)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        dic=dict(Counter(nums))\n",
    "        res=[0,0]\n",
    "        res[0]=sum(item//2 for item in list(dic.values()))\n",
    "        res[1]=len(nums)-2*res[0]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        tmp=Counter(nums)\n",
    "        res=0\n",
    "        unpart=0\n",
    "        for i,v in tmp.items():\n",
    "            if v%2!=0:\n",
    "                unpart+=1\n",
    "            res+=v//2\n",
    "        return [res, unpart]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        a, b = 0, 0\n",
    "        for v in Counter(nums).values():\n",
    "            a += v // 2\n",
    "            b += v % 2\n",
    "\n",
    "        return [a, b]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        a=len(nums);cnt=0\n",
    "        for i in range(a-1):\n",
    "            for j in range(i+1,a):\n",
    "                if nums[i]==nums[j] and nums[i]>=0:\n",
    "                    cnt+=1\n",
    "                    nums[i]=nums[j]=-1\n",
    "        list=[cnt,a-cnt*2]\n",
    "        return(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        counter=dict()\n",
    "        for num in nums:\n",
    "            counter[num] = counter.get(num, 0) + 1\n",
    "        counter1=dict()\n",
    "        sum1=0\n",
    "        for key in counter:\n",
    "            counter1[key]=counter1.get(key,counter[key]%2)\n",
    "            sum1+=counter1[key]\n",
    "        counter2=dict()\n",
    "        sum2=0\n",
    "        for key in counter:\n",
    "            counter2[key]=counter2.get(key,counter[key]//2)\n",
    "            sum2+=counter2[key]\n",
    "        return [sum2,sum1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        ans1, ans2 = 0, 0\n",
    "        dic = defaultdict(int)\n",
    "        for i in nums:\n",
    "            dic[i] += 1\n",
    "        for i in dic:\n",
    "            if dic[i] % 2 == 0:\n",
    "                ans1 += dic[i] // 2\n",
    "            else:\n",
    "                ans1 += dic[i] // 2\n",
    "                ans2 += 1\n",
    "        return [ans1, ans2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        answer0 = 0\n",
    "        answer1 = 0\n",
    "\n",
    "        c = collections.Counter(nums)\n",
    "        for i in c.values():\n",
    "            answer0 += i // 2\n",
    "            answer1 += i % 2\n",
    "        return [answer0, answer1]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        res=[0,0]\n",
    "        counter=Counter(nums)\n",
    "        for k in counter:\n",
    "            num=counter[k]\n",
    "            res[0]+=num//2\n",
    "            res[1]+=num%2\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        h = Counter(nums)\n",
    "        s = sum(v // 2 for v in h.values())\n",
    "        return [s, len(nums)- s*2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        nums_counter = Counter(nums)\n",
    "        res = [0,0]\n",
    "        for i in nums_counter.values():\n",
    "            if i % 2 ==1:\n",
    "                res[1]+=1\n",
    "            res[0]+=i//2\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        count = defaultdict(bool)\n",
    "        res = 0\n",
    "        for num in nums:\n",
    "            count[num] = not count[num]\n",
    "            if not count[num]:\n",
    "                res += 1\n",
    "        return [res, len(nums) - 2 * res]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        nums.sort()\n",
    "        id1 = 0\n",
    "        id2 = 1\n",
    "        counts = 0\n",
    "        while id2 < len(nums):\n",
    "            if nums[id1] == nums[id2]:\n",
    "                del nums[id1]\n",
    "                del nums[id1]\n",
    "                counts += 1\n",
    "            else:\n",
    "                id1 += 1\n",
    "                id2 += 1\n",
    "        return [counts, len(nums)]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        a1 = 0\n",
    "        a2 = 0\n",
    "        b = [0] * 101\n",
    "        for i in range(len(nums)):\n",
    "            b[nums[i]] = b[nums[i]] + 1\n",
    "        for i in range(101):\n",
    "            a1 = a1 + int(b[i]/2)\n",
    "            if b[i] % 2 == 1:\n",
    "                a2 = a2 + 1\n",
    "        return [a1, a2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        cnt = defaultdict(bool)\n",
    "        res = 0\n",
    "        for num in nums:\n",
    "            cnt[num] = not cnt[num]\n",
    "            if not cnt[num]:\n",
    "                res += 1\n",
    "        return [res, len(nums) - 2 * res]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        import collections\n",
    "        nums_dict = collections.Counter(nums)\n",
    "        count = 0\n",
    "        for k, v in nums_dict.items():\n",
    "            count += v//2\n",
    "        return [count, len(nums) - count * 2] \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        cnt1 = 0\n",
    "        cnt2 = 0\n",
    "        dis = {}\n",
    "        for num in nums:\n",
    "            if num not in dis:\n",
    "                dis[num] = 1\n",
    "            else:\n",
    "                dis[num] += 1\n",
    "        for key, value in dis.items():\n",
    "            if value % 2 != 0:\n",
    "                cnt2 += 1\n",
    "                cnt1 += value // 2\n",
    "            else:\n",
    "                cnt1 += value//2\n",
    "        return [cnt1, cnt2]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        stack = []\n",
    "        n = 0\n",
    "        for num in nums:\n",
    "            if num not in stack:\n",
    "                stack.append(num)\n",
    "            else:\n",
    "                stack.remove(num)\n",
    "                n += 1\n",
    "        return [n, len(stack)]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        count = Counter(nums)\n",
    "        count_nums = sum(i // 2 for i in count.values())\n",
    "        return [count_nums , len(nums) - count_nums * 2]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        if len(nums)<2:\n",
    "            return [0,len(nums)]\n",
    "        else:\n",
    "            a=[]\n",
    "            for i in nums:\n",
    "                if i not in a:\n",
    "                    a.append(i)\n",
    "            print(a)\n",
    "            b=[]\n",
    "            for i in a:\n",
    "                b.append(nums.count(i))\n",
    "            print(b)\n",
    "            n1=n2=0\n",
    "            for i in range(len(b)):\n",
    "                n1=n1+b[i]//2\n",
    "                n2=n2+b[i]%2\n",
    "            print(n1,n2)\n",
    "            return [n1,n2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        count = 0\n",
    "        dict_map = {}\n",
    "        for num in nums:\n",
    "            if num in dict_map:\n",
    "                count += 1\n",
    "                dict_map.pop(num)\n",
    "            else:\n",
    "                dict_map[num] = None\n",
    "        return [count, len(dict_map)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        cnt = defaultdict(bool)\n",
    "        res = 0\n",
    "        for num in nums:\n",
    "            cnt[num] = not cnt[num]\n",
    "            if not cnt[num]:\n",
    "                res += 1\n",
    "        return [res, len(nums) - 2 * res]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        num_dict = Counter(nums)\n",
    "        result = [0, 0]\n",
    "        for key in num_dict:\n",
    "            result[0] += num_dict[key] // 2\n",
    "            result[1] += num_dict[key] % 2\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        s = set()\n",
    "        count = rest = 0\n",
    "        for num in nums:\n",
    "            if num in s:\n",
    "                s.remove(num)\n",
    "                count = count +1\n",
    "            else:\n",
    "                s.add(num)\n",
    "        return [count, len(s)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        dic = collections.Counter(nums)\n",
    "        return [sum(i // 2 for i in dic.values()),sum(1 for i in dic.values() if i % 2)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        pair, left, c = 0, 0, Counter(nums)\n",
    "        for k, v in c.items():\n",
    "            if v % 2:\n",
    "                left += 1\n",
    "            pair += v // 2\n",
    "        return [pair, left]\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        new_nums = list(set(nums))\n",
    "        pre = 0\n",
    "        end = 0\n",
    "        for i in new_nums:\n",
    "            i_count = nums.count(i)\n",
    "            if i_count  % 2 == 0:\n",
    "                pre += i_count // 2\n",
    "            else:\n",
    "                if i_count > 2:\n",
    "                    pre += i_count// 2\n",
    "                end += 1\n",
    "        print([pre,end])\n",
    "        return [pre,end]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        cnt = defaultdict(bool)\n",
    "        res=0\n",
    "        for num in nums:\n",
    "            cnt[num]=not cnt[num]\n",
    "            if not cnt[num]:\n",
    "                res+=1\n",
    "        return [res,len(nums)-2*res]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        cnt = defaultdict(bool)\n",
    "        res = 0\n",
    "        for num in nums:\n",
    "            cnt[num] = not cnt[num]\n",
    "            if not cnt[num]:\n",
    "                res += 1\n",
    "        return [res, len(nums) - 2 * res]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        dic = Counter(nums)\n",
    "        s = sum(v // 2 for v in dic.values())\n",
    "        return [s, len(nums)- 2*s]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        c = Counter(nums)\n",
    "        a = sum(c[x]//2 for x in c)\n",
    "        b = len(nums) - a * 2\n",
    "        return [a, b]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        cnt = Counter(nums)\n",
    "        s = sum(i//2 for i in cnt.values())\n",
    "        return[s,len(nums) - s*2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        ans = [0, 0]\n",
    "        nums = sorted(nums)\n",
    "        if len(nums) == 1:\n",
    "            return [0, 1]\n",
    "        i = 0\n",
    "        while i < (len(nums) - 1):\n",
    "            if nums[i] == nums[i+1]:\n",
    "                ans[0] += 1\n",
    "                nums.pop(i)\n",
    "                nums.pop(i)\n",
    "            else:\n",
    "                i += 1\n",
    "        ans[1] = len(nums)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        count = 0\n",
    "        for i in set(nums):\n",
    "            count += nums.count(i) // 2\n",
    "        return [count,n-2*count]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        n=len(nums)\n",
    "        nums.insert(0,0)\n",
    "        temp_n=n\n",
    "        last=temp_n//2\n",
    "        while last>=1:\n",
    "            i=last\n",
    "            while i * 2 <= temp_n:\n",
    "                if i * 2 == temp_n:\n",
    "                    if nums[i * 2] > nums[i]:\n",
    "                        temp = nums[i * 2]\n",
    "                        nums[i * 2] = nums[i]\n",
    "                        nums[i] = temp\n",
    "                    break\n",
    "                if nums[i * 2] > nums[i * 2 + 1]:\n",
    "                    if nums[i * 2] > nums[i]:\n",
    "                        temp = nums[i]\n",
    "                        nums[i] = nums[i * 2]\n",
    "                        nums[i * 2] = temp\n",
    "                        i *= 2\n",
    "                    else:\n",
    "                        break\n",
    "                else:\n",
    "                    if nums[i * 2 + 1] > nums[i]:\n",
    "                        temp = nums[i]\n",
    "                        nums[i] = nums[i * 2 + 1]\n",
    "                        nums[i * 2 + 1] = temp\n",
    "                        i = i * 2 + 1\n",
    "                    else:\n",
    "                        break\n",
    "            last-=1\n",
    "        while temp_n>=1:\n",
    "            temp=nums[1]\n",
    "            nums[1]=nums[temp_n]\n",
    "            nums[temp_n]=temp\n",
    "            temp_n-=1\n",
    "            i=1\n",
    "            while i * 2 <= temp_n:\n",
    "                if i * 2 == temp_n:\n",
    "                    if nums[i * 2] > nums[i]:\n",
    "                        temp = nums[i * 2]\n",
    "                        nums[i * 2] = nums[i]\n",
    "                        nums[i] = temp\n",
    "                    break\n",
    "                if nums[i * 2] > nums[i * 2 + 1]:\n",
    "                    if nums[i * 2] > nums[i]:\n",
    "                        temp = nums[i]\n",
    "                        nums[i] = nums[i * 2]\n",
    "                        nums[i * 2] = temp\n",
    "                        i *= 2\n",
    "                    else:\n",
    "                        break\n",
    "                else:\n",
    "                    if nums[i * 2 + 1] > nums[i]:\n",
    "                        temp = nums[i]\n",
    "                        nums[i] = nums[i * 2 + 1]\n",
    "                        nums[i * 2 + 1] = temp\n",
    "                        i = i * 2 + 1\n",
    "                    else:\n",
    "                        break\n",
    "        i=1\n",
    "        same=0\n",
    "        while i<n:\n",
    "            if nums[i]==nums[i+1]:\n",
    "                same+=1\n",
    "                i+=2\n",
    "            else:\n",
    "                i+=1\n",
    "        return [same,n-2*same]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        count = {}\n",
    "        for num in nums:\n",
    "            count[num] = count.get(num, 0) + 1\n",
    "        #{1:2, 2:3, 3:2}\n",
    "        pair, left = 0, 0\n",
    "        for num in count:\n",
    "            pair += count[num] // 2\n",
    "            if count[num] % 2 != 0:\n",
    "                left += 1\n",
    "\n",
    "        return [pair, left]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        ans = 0\n",
    "        n = len(nums)\n",
    "        count = set()\n",
    "        for item in nums:\n",
    "            if item in count:\n",
    "                count.remove(item)\n",
    "                ans += 1\n",
    "            else:\n",
    "                count.add(item)\n",
    "        return [ans,n-2*ans]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        dic = Counter(nums)\n",
    "        ans = len(nums)\n",
    "        for key in dic:\n",
    "            if dic[key] >= 0:\n",
    "                ans -= dic[key] - dic[key] % 2\n",
    "        return [(len(nums)-ans)//2, ans]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        dic = Counter(nums)\n",
    "        s = sum([v//2 for v in dic.values()])\n",
    "        return (s,len(nums)-s*2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        cnt = Counter(nums)\n",
    "        s = sum(v // 2 for v in cnt.values())\n",
    "        return [s, len(nums) - s * 2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        cnt = Counter(nums)\n",
    "        s = sum(v//2 for v in cnt.values())\n",
    "        return [s,len(nums)-2*s]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        pairs = {}\n",
    "        for num in nums:\n",
    "            if num in pairs:\n",
    "                pairs[num] += 1\n",
    "            else:\n",
    "                pairs[num] = 1\n",
    "        \n",
    "        final = [0, 0]\n",
    "        for k, v in pairs.items():\n",
    "            final[0] += int(v / 2)\n",
    "            final[1] += v % 2\n",
    "        \n",
    "        return final\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        dic = Counter(nums)\n",
    "        a = 0\n",
    "        for v in dic.values():\n",
    "            a += v // 2\n",
    "        return [a, len(nums) - a * 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        if len(nums)==1:\n",
    "            return [0,1]\n",
    "        elif len(nums)==2:\n",
    "            if nums[0]==nums[1]:\n",
    "                return [1,0]\n",
    "            else:\n",
    "                return [0,2]\n",
    "        dic={}\n",
    "        for i in nums:\n",
    "            if i not in dic:\n",
    "                dic[i]=1\n",
    "            else:\n",
    "                dic[i]+=1\n",
    "        k,v=0,0\n",
    "        for s in dic.values():\n",
    "            if s>=2:\n",
    "                k+=int(s/2)\n",
    "                v+=s%2\n",
    "            else:\n",
    "                v+=s       \n",
    "        return [k,v]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        d = Counter(nums)\n",
    "        a = b = 0\n",
    "        for n, cnt in d.items():\n",
    "            x, y = divmod(cnt, 2)\n",
    "            a += x\n",
    "            b += y\n",
    "        return [a, b]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "\n",
    "        count = [0] * 101\n",
    "\n",
    "        for num in nums:\n",
    "            count[num] += 1\n",
    "\n",
    "        res = [0, 0]\n",
    "\n",
    "        for num, cnt in enumerate(count):\n",
    "            res[0] += cnt // 2\n",
    "            res[1] += cnt % 2 \n",
    "\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        nums_len , nums_count = len(nums) , 0\n",
    "        s = set(nums)\n",
    "        my_counter = Counter(nums)\n",
    "        for cnt in my_counter.values():\n",
    "            if cnt >= 2:\n",
    "                tmp = cnt // 2\n",
    "                nums_count += tmp\n",
    "                nums_len -= tmp * 2\n",
    "        return [nums_count,nums_len]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "\n",
    "        count = [0] * 101\n",
    "\n",
    "        for num in nums:\n",
    "            count[num] += 1\n",
    "\n",
    "        x = 0\n",
    "\n",
    "        for num, cnt in enumerate(count):\n",
    "            x += cnt // 2\n",
    "\n",
    "        return [x, n - 2 * x]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        nums1 = Counter(nums)\n",
    "        tim = 0\n",
    "        for i in nums1.values():\n",
    "            tim += i // 2\n",
    "        return [tim, len(nums) - tim*2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        a, b = 0, 0\n",
    "        cnt = Counter(nums)\n",
    "        for key in cnt.keys():\n",
    "            a += int(cnt[key]/2)\n",
    "            b += 0 if cnt[key]%2 == 0 else 1\n",
    "        return [a, b]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        m, n = [], 0\n",
    "        for i in nums:\n",
    "            if i not in m:\n",
    "                m.append(i)\n",
    "            else:\n",
    "                m.remove(i)\n",
    "                n+=1\n",
    "        return [n, len(nums)-2*n]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        ans=0\n",
    "        res=0\n",
    "        c=Counter(nums)\n",
    "        print(c)\n",
    "        for num,cnt in c.items():\n",
    "            if cnt>=2:\n",
    "                ans+=cnt//2\n",
    "            res+=cnt%2\n",
    "        return [ans,res]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        nums.sort()\n",
    "        counter = 0\n",
    "\n",
    "        while len(nums)!=len(set(nums)):\n",
    "            for i in range(len(nums)-1):\n",
    "                for j in range(i+1, len(nums)):\n",
    "                    if nums[i]==nums[j]:\n",
    "                        counter+=1\n",
    "                        nums.pop(j)\n",
    "                        nums.pop(i)\n",
    "                        break\n",
    "            \n",
    "        return [counter, len(nums)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        dic=Counter(nums)\n",
    "        count=0\n",
    "        for k,v in dic.items():\n",
    "            count+=v//2\n",
    "        print(count)\n",
    "        return [count,len(nums)-2*count]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        cnt = Counter(nums)\n",
    "        s = sum(v // 2 for v in cnt.values())\n",
    "        return [s, len(nums) - s * 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        aa=[i for i,j in Counter(nums).items() if j%2!=0]\n",
    "        set1=set(nums)\n",
    "        return((len(nums)-len(aa))//2,len(aa))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numberOfPairs(self, nums: List[int]) -> List[int]:\n",
    "        count = 0\n",
    "        res = []\n",
    "        for i in nums:\n",
    "            if i in res:\n",
    "                count += 1\n",
    "                res.remove(i)\n",
    "            elif i not in res:\n",
    "                res.append(i)\n",
    "        return [count,len(res)]"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
